package com.jidesoft.example;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jidesoft.icons.JideIconsFactory;
import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.JideBorderLayout;
import com.jidesoft.swing.JideSwingUtilities;
import com.jidesoft.swing.JideTabbedPane;

public class JideBorderLayoutDemo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		LookAndFeelFactory.installDefaultLookAndFeelAndExtension();

		JFrame frame = new JFrame("Test");
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.out.println("关闭");
			}
		});

		frame.setIconImage(JideIconsFactory.getImageIcon(
				JideIconsFactory.JIDE32).getImage());
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel panel1 = createJideBorderLayoutPanel();
		JPanel panel2 = createBorderLayoutPanel();

		JideTabbedPane tabbedPane = new JideTabbedPane();
		tabbedPane.setTabShape(JideTabbedPane.SHAPE_BOX);
		tabbedPane.add(panel1);
		tabbedPane.add(panel2);

		frame.getContentPane().setLayout(new BorderLayout());
		frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

		frame.pack();
		JideSwingUtilities.globalCenterWindow(frame);
		frame.setVisible(true);
		frame.toFront();
	}

	private static JPanel createJideBorderLayoutPanel() {
		JPanel panel = new JPanel(new JideBorderLayout(6, 10));
		panel.setName("JideBorderLayout");
		JButton button = new JButton("NORTH");
		panel.add(button, JideBorderLayout.BEFORE_FIRST_LINE);
		button = new JButton("SOUTH");
		panel.add(button, JideBorderLayout.AFTER_LAST_LINE);
		button = new JButton("WEST");
		panel.add(button, JideBorderLayout.BEFORE_LINE_BEGINS);
		button = new JButton("EAST");
		panel.add(button, JideBorderLayout.AFTER_LINE_ENDS);
		button = new JButton("CENTER");
		button.setPreferredSize(new Dimension(200, 200));
		panel.add(button, JideBorderLayout.CENTER);
		panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		return panel;
	}

	private static JPanel createBorderLayoutPanel() {
		JPanel panel = new JPanel(new BorderLayout(6, 10));
		panel.setName("BorderLayout");
		JButton button = new JButton("NORTH");
		panel.add(button, JideBorderLayout.BEFORE_FIRST_LINE);
		button = new JButton("SOUTH");
		panel.add(button, JideBorderLayout.AFTER_LAST_LINE);
		button = new JButton("WEST");
		panel.add(button, JideBorderLayout.BEFORE_LINE_BEGINS);
		button = new JButton("EAST");
		panel.add(button, JideBorderLayout.AFTER_LINE_ENDS);
		button = new JButton("CENTER");
		button.setPreferredSize(new Dimension(200, 200));
		panel.add(button, JideBorderLayout.CENTER);
		panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		return panel;
	}

}
